package com.tedu.openmedical.duplicate.copy_content.service.impl;

import com.tedu.openmedical.duplicate.copy_content.mapper.CopyContentMapper;
import com.tedu.openmedical.duplicate.copy_content.pojo.dto.ContentParam;
import com.tedu.openmedical.duplicate.copy_content.pojo.dto.ContentQuery;
import com.tedu.openmedical.duplicate.copy_content.pojo.entity.CopyContent;
import com.tedu.openmedical.duplicate.copy_content.pojo.vo.CopyContentVO;
import com.tedu.openmedical.duplicate.copy_content.service.CopyContentService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class CopyContentServiceImpl implements CopyContentService {
    @Autowired
    private CopyContentMapper copyContentMapper;

    @Override
    public List<CopyContentVO> loadContent(ContentQuery query) {
        List<CopyContentVO> list=copyContentMapper.loadContent(query);
        return list;
    }
    @Override
    public void updateContent(ContentParam param) {
        CopyContent content=new CopyContent();
        BeanUtils.copyProperties(param,content);
        if(param.getId()==null){
            //走新增流程
            log.debug("新增流程");
            content.setCreateTime(new Date());
            copyContentMapper.insertContent(content);
        }
        else{
            //走更新流程
            copyContentMapper.updateContent(content);
        }
    }
    @Override
    public void deleteContent(Integer id){
        copyContentMapper.deleteContent(id);
    }
}
